package Servlet.Manager;

import Dao.FindBorrowBookDao;
import Table.Book;
import com.alibaba.fastjson.JSON;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/managerFindBorrowBookServlet")
public class ManagerFindBorrowBookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        ArrayList<Book> list = FindBorrowBookDao.FindBorrowBook(Integer.parseInt(id));
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String s = JSON.toJSONString(list);
        out.print(s);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
